package com.baor.service.impl;

import com.baor.dao.GoodsDao;
import com.baor.dao.OrderDao;
import com.baor.dao.OrderLogDao;
import com.baor.domain.OrderVo;
import com.baor.domain.conf.DistributionConf;
import com.baor.service.CopyService;
import com.baor.utils.AjaxResult;
import com.baor.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.TimeUnit;


@Service
public class CopyServiceImpl implements CopyService {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderLogDao orderLogDao;

    @Autowired
    private GoodsDao goodsDao;


    @Override
    public AjaxResult<?> insertOrder(OrderVo vo) {//设置固定时间失效
        if ( vo.getOrderId() == null )
            return AjaxResult.error("无效订单",null);
        this.redisUtil.setValue("orderId-"+vo.getOrderId(),vo,10,TimeUnit.MINUTES);
        return AjaxResult.success();
    }

    @Override
    public AjaxResult<?> payMoney(OrderVo vo) {
        Object value = this.redisUtil.getValue("orderId-" + vo.getOrderId());
        if ( value == null )
            return AjaxResult.error("订单失效",null);
        OrderVo x = (OrderVo) value;
        //更新订单状态
        return AjaxResult.success(x);
    }
}
